import { debounce, throttle } from 'lodash'
import { useSnapshotStore } from '@/store'

/**
 * @description: 历史快照
 */
export class HistorySnapshot {
  static get store() {
    return useSnapshotStore()
  }
  // 添加历史快照(历史记录)
  static add = debounce(
    function() {
      HistorySnapshot.store.addSnapshot()
    },
    300,
    { trailing: true },
  )

  // 重做
  static redo = throttle(
    function() {
      HistorySnapshot.store.reDo()
    },
    100,
    { leading: true, trailing: false },
  )

  // 撤销
  static undo = throttle(
    function() {
      HistorySnapshot.store.unDo()
    },
    100,
    { leading: true, trailing: false },
  )
}
